/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newspaperSystem.Update;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.*;
import net.proteanit.sql.DbUtils;

/**
 *
 * @author Leo
 */
public class update extends javax.swing.JFrame implements ActionListener {

    /**
     * Creates new form update
     */
    private ButtonGroup btnG = new ButtonGroup();

    public update() {
        initComponents();
        btnG.add(jRadioButton1);
        btnG.add(jRadioButton2);
        btnG.add(jRadioButton3);
        btnG.add(jRadioButton4);
        btnG.add(jRadioButton5);
        btnG.add(jRadioButton6);
        btnG.add(jRadioButton7);

        jRadioButton1.addActionListener(this);
        jRadioButton2.addActionListener(this);
        jRadioButton3.addActionListener(this);
        jRadioButton4.addActionListener(this);
        jRadioButton5.addActionListener(this);
        jRadioButton6.addActionListener(this);
        jRadioButton7.addActionListener(this);

        jButton1.addActionListener(this);
        jButton2.addActionListener(this);
        jButton3.addActionListener(this);
        jButton4.addActionListener(this);
        jButton5.addActionListener(this);
        jButton6.addActionListener(this);
        jButton7.addActionListener(this);
        jButton8.addActionListener(this);

        jTextField10.setEditable(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        table_Update = new javax.swing.JTable();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jTextField9 = new javax.swing.JTextField();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jTextField10 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        table_Update.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4", "Title 5", ""
            }
        ));
        table_Update.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                table_UpdateMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(table_Update);

        jRadioButton1.setText("Carriers");

        jRadioButton2.setText("Customers");

        jRadioButton3.setText("Products");

        jRadioButton4.setText("Bill");

        jRadioButton5.setText("Suppliers");

        jRadioButton6.setText("Routes");

        jRadioButton7.setText("Subscription");

        jLabel1.setText("Name:");

        jLabel2.setText("Surname:");

        jLabel3.setText("Phone#:");

        jLabel4.setText("Description:");

        jLabel5.setText("Addess:");

        jLabel6.setText("Surbab:");

        jLabel7.setText("Type:");

        jLabel8.setText("Date:");

        jLabel9.setText("Amount:");

        jToolBar1.setRollover(true);

        jButton1.setText("Carriers");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);

        jButton2.setText("Customers");
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton2);

        jButton3.setText("Products");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton3);

        jButton4.setText("Bill");
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton4);

        jButton5.setText("Suppliers");
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton5);

        jButton6.setText("Routes");
        jToolBar1.add(jButton6);

        jButton7.setText("Subscription");
        jButton7.setFocusable(false);
        jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton7);

        jButton8.setText("Back to main");

        jLabel10.setFont(new java.awt.Font("Tahoma", 3, 12)); // NOI18N
        jLabel10.setText("Choose and click 1 button bellow to update record");

        jLabel11.setText("ID:");

        jTextField10.setEnabled(false);

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel12.setText("Update Data");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton8)
                        .addGap(382, 382, 382))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel3)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel1)
                                        .addComponent(jLabel11))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jTextField1)
                                        .addComponent(jTextField10, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton1)
                                    .addComponent(jRadioButton3)
                                    .addComponent(jRadioButton5))
                                .addGap(29, 29, 29)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton6)
                                    .addComponent(jRadioButton4)
                                    .addComponent(jRadioButton2)))
                            .addComponent(jRadioButton7))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 567, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(99, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField5))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel6)
                                            .addComponent(jLabel8)
                                            .addComponent(jLabel9))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jTextField6)
                                            .addComponent(jTextField7)
                                            .addComponent(jTextField8)
                                            .addComponent(jTextField9, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE))))
                                .addGap(50, 50, 50)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(131, 131, 131))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(8, 8, 8)
                                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap())))))))
            .addGroup(layout.createSequentialGroup()
                .addGap(344, 344, 344)
                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButton1)
                            .addComponent(jRadioButton2))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButton3)
                            .addComponent(jRadioButton4))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButton5)
                            .addComponent(jRadioButton6))
                        .addGap(18, 18, 18)
                        .addComponent(jRadioButton7)
                        .addGap(25, 25, 25))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel12)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(7, 7, 7))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel3)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(jButton8)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void table_UpdateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_table_UpdateMouseClicked

        // TODO add your handling code here:
        Locale loc = Locale.getDefault();
        ResourceBundle bundle = ResourceBundle.getBundle("database", loc);
        String url = bundle.getString("URL");
        String user = bundle.getString("username");
        String pw = bundle.getString("password");
        String driver = bundle.getString("Driver");
        Connection conn = null;
        PreparedStatement stmt = null;

        //PreparedStatement pstmnt;

        ResultSet resultSet = null;

        try {

            Class.forName(driver);
            System.out.println("Driver loaded succesfully!!!");


        } catch (ClassNotFoundException classNotFound) {

            System.out.println("OOps class not found:" + classNotFound);
        }

        try {


            conn = DriverManager.getConnection(url, user, pw);

            System.out.println("Connection successful");
            try {

                int row = table_Update.getSelectedRow();
                String tableClick = (table_Update.getModel().getValueAt(row, 0).toString());
                String sql1 = "Select * from Carrier where Carrier_Id='" + tableClick + "'";

                stmt = conn.prepareStatement(sql1);
                resultSet = stmt.executeQuery();
                if (resultSet.next()) {

                    String id = resultSet.getString("Carrier_id");
                    jTextField10.setText(id);
                    String name = resultSet.getString("Carrier_Name");
                    jTextField1.setText(name);
                    String sname = resultSet.getString("Carrier_Surname");
                    jTextField2.setText(sname);
                    String phne = resultSet.getString("Phone_Num");
                    jTextField3.setText(phne);
                    String addr = resultSet.getString("Address");
                    jTextField5.setText(addr);
                    String surb = resultSet.getString("Surbab");
                    jTextField6.setText(surb);
                }



                //Customer

                String sql2 = "Select * from Customer where Cust_Id='" + tableClick + "'";
                stmt = conn.prepareStatement(sql2);
                resultSet = stmt.executeQuery();
                if (resultSet.next()) {

                    String id = resultSet.getString("cust_id");
                    jTextField10.setText(id);
                    String name = resultSet.getString("Cust_Name");
                    jTextField1.setText(name);
                    String sname = resultSet.getString("Cust_Surname");
                    jTextField2.setText(sname);
                    String phne = resultSet.getString("Phone_Num");
                    jTextField3.setText(phne);
                    String addr = resultSet.getString("Address");
                    jTextField5.setText(addr);
                    String surb = resultSet.getString("Surbab");
                    jTextField6.setText(surb);
                }

                String sql3 = "Select * from Product where Prod_Id='" + tableClick + "'";
                stmt = conn.prepareStatement(sql3);
                resultSet = stmt.executeQuery();
                if (resultSet.next()) {

                    String id = resultSet.getString("prod_id");
                    jTextField10.setText(id);
                    String descr = resultSet.getString("prod_descr");
                    jTextField4.setText(descr);
                    String price = resultSet.getString("prod_price");
                    jTextField9.setText(price);

                }
                String sql4 = "Select * from Bill where cust_Id='" + tableClick + "'";
                stmt = conn.prepareStatement(sql4);
                resultSet = stmt.executeQuery();
                if (resultSet.next()) {

                    String id = resultSet.getString("Cust_id");
                    jTextField10.setText(id);
                    String name = resultSet.getString("cust_name");
                    jTextField1.setText(name);
                    String type = resultSet.getString("subscr_type");
                    jTextField7.setText(type);
                    String amnt = resultSet.getString("amount");
                    jTextField9.setText(amnt);
                }
                String sql5 = "Select * from Suppliers where supp_id='" + tableClick + "'";
                stmt = conn.prepareStatement(sql5);
                resultSet = stmt.executeQuery();
                if (resultSet.next()) {

                    String id = resultSet.getString("supp_id");
                    jTextField10.setText(id);
                    String supp_name = resultSet.getString("supp_name");
                    jTextField1.setText(supp_name);
                    String date = resultSet.getString("supp_date");
                    jTextField8.setText(date);

                }
                String sql6 = "Select * from Routes where route_num='" + tableClick + "'";
                stmt = conn.prepareStatement(sql6);
                resultSet = stmt.executeQuery();
                if (resultSet.next()) {

                    String id = resultSet.getString("route_num");
                    jTextField10.setText(id);
                    String supp_name = resultSet.getString("route_name");
                    jTextField1.setText(supp_name);
                    String descr = resultSet.getString("descr");
                    jTextField4.setText(descr);
                    String addr = resultSet.getString("address");
                    jTextField5.setText(addr);
                    String surb = resultSet.getString("surbab");
                    jTextField6.setText(surb);
                }
                String sql7 = "Select * from Subscription where subscr_id='" + tableClick + "'";
                stmt = conn.prepareStatement(sql7);
                resultSet = stmt.executeQuery();
                if (resultSet.next()) {

                    String id = resultSet.getString("subscr_id");
                    jTextField10.setText(id);
                    String type = resultSet.getString("subscr_type");
                    jTextField7.setText(type);
                    String descr = resultSet.getString("descr");
                    jTextField4.setText(descr);

                }

            } catch (Exception e) {

                JOptionPane.showMessageDialog(null, e);
            }
        } catch (SQLException ex) {
            System.out.println("");
        } finally {

            try {
                if (resultSet != null) {
                    resultSet.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
                if (conn != null) {
                    conn.close();
                }

            } catch (Exception exception) {
                System.out.println("Something went wrong along the way");
            }
        }


    }//GEN-LAST:event_table_UpdateMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(update.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(update.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(update.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(update.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new update().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTable table_Update;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent e) {


        Locale loc = Locale.getDefault();
        ResourceBundle bundle = ResourceBundle.getBundle("database", loc);
        String url = bundle.getString("URL");
        String user = bundle.getString("username");
        String pw = bundle.getString("password");
        String driver = bundle.getString("Driver");
        Connection conn = null;
        PreparedStatement stmt = null;
        Statement psmt = null;

        //PreparedStatement pstmnt;

        ResultSet resultSet = null;

        try {

            Class.forName(driver);
            System.out.println("Driver loaded succesfully!!!");


        } catch (ClassNotFoundException classNotFound) {

            System.out.println("OOps class not found:" + classNotFound);
        }

        try {


            conn = DriverManager.getConnection(url, user, pw);

            System.out.println("Connection successful");

            if (e.getSource() == jRadioButton1) {
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
                jTextField7.setText("");
                String sqlstmt = "Select * from Carrier";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Update.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton2) {
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
                jTextField7.setText("");
                String sqlstmt = "Select * from Customer";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Update.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton3) {
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
                jTextField7.setText("");
                String sqlstmt = "Select * from Product";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Update.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton4) {
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
                jTextField7.setText("");
                String sqlstmt = "Select * from Bill";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Update.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton5) {
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
                jTextField7.setText("");
                String sqlstmt = "Select * from Suppliers";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Update.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton6) {
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
                jTextField7.setText("");
                String sqlstmt = "Select * from Routes";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Update.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton7) {
                jTextField1.setText("");
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
                jTextField7.setText("");
                String sqlstmt = "Select * from Subscription";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Update.setModel(DbUtils.resultSetToTableModel(resultSet));
            }
            if (e.getSource() == jButton1) {

                try {
                    String field1 = jTextField10.getText();


                    String field3 = jTextField1.getText();
                    String field4 = jTextField2.getText();
                    String field5 = jTextField3.getText();
                    String field7 = jTextField5.getText();
                    String field8 = jTextField6.getText();
                    psmt = conn.createStatement();

                    String sqlUpdate = "Update Carrier set Carrier_Name='" + (field3) + "',Carrier_Surname='" + (field4)
                            + "',Phone_Num='" + (field5) + "',Address='" + (field7) + "',Surbab='" + (field8) + "' Where Carrier_Id='" + (field1) + "'";

                    psmt.executeUpdate(sqlUpdate);

                    JOptionPane.showMessageDialog(null, "Table Carriers Updated");

                    jTextField10.setText("");
                    jTextField1.setText("");
                    jTextField2.setText("");
                    jTextField3.setText("");
                    jTextField5.setText("");
                    jTextField6.setText("");
                } catch (Exception ev) {

                    JOptionPane.showMessageDialog(null, "'You may INSERT from Carrier table only during normal business hours");
                }
            }
            if (e.getSource() == jButton2) {

                try {
                    String field1 = jTextField10.getText();


                    String field3 = jTextField1.getText();
                    String field4 = jTextField2.getText();
                    String field5 = jTextField3.getText();
                    String field7 = jTextField5.getText();
                    String field8 = jTextField6.getText();

                    psmt = conn.createStatement();

                    String sqlUpdate = "Update Customer set Cust_Name='" + (field3) + "',Cust_Surname='" + (field4)
                            + "',Phone_Num='" + (field5) + "',Address='" + (field7) + "',Surbab='" + (field8) + "' Where Cust_Id='" + (field1) + "'";

                    psmt.executeUpdate(sqlUpdate);

                    JOptionPane.showMessageDialog(null, "Table Customer Updated");

                    jTextField10.setText("");
                    jTextField1.setText("");
                    jTextField2.setText("");
                    jTextField3.setText("");
                    jTextField5.setText("");
                    jTextField6.setText("");
                } catch (Exception ev) {

                    JOptionPane.showMessageDialog(null, "You may Update Customer table only during normal business hours");
                }

            }
            if (e.getSource() == jButton3) {

                try {
                    String field1 = jTextField10.getText();


                    String field3 = jTextField4.getText();
                    String field4 = jTextField9.getText();
                    psmt = conn.createStatement();

                    String sqlUpdate = "Update Product set Prod_Descr='" + (field3) + "',Prod_Price='" + (field4) + "' Where Prod_Id='" + (field1) + "'";

                    psmt.executeUpdate(sqlUpdate);

                    JOptionPane.showMessageDialog(null, "Table Product Updated");
                    jTextField10.setText("");
                    jTextField4.setText("");
                    jTextField9.setText("");
                } catch (Exception ev) {

                    JOptionPane.showMessageDialog(null, "'You may Update Product table only during normal business hours");
                }

            } else if (e.getSource() == jButton4) {

                try {
                    String field1 = jTextField10.getText();


                    String field3 = jTextField1.getText();
                    String field4 = jTextField7.getText();
                    String field5 = jTextField9.getText();
                    psmt = conn.createStatement();
                    String sqlUpdate = "Update Bill set Cust_Name='" + (field3) + "',Subscr_Type='" + (field4) + "',amount='" + (field5) + "' Where Cust_Id='" + (field1) + "'";

                    psmt.executeUpdate(sqlUpdate);

                    JOptionPane.showMessageDialog(null, "Table Bill Updated");
                    jTextField10.setText("");
                    jTextField9.setText("");
                    jTextField3.setText("");
                    jTextField9.setText("");
                } catch (Exception ev) {

                    JOptionPane.showMessageDialog(null, "You may Update Bill table only during normal business hours");
                }
            } else if (e.getSource() == jButton5) {

                try{
                String field1 = jTextField10.getText();

                String field3 = jTextField1.getText();
                String date = jTextField8.getText();
                psmt = conn.createStatement();
                String sqlUpdate = "Update Suppliers set Supp_Name='" + (field3) + "',Supp_Date='" + (date) + "' Where Supp_id='" + (field1) + "'";

                psmt.executeUpdate(sqlUpdate);

                JOptionPane.showMessageDialog(null, "Table Suppliers Updated");
                jTextField10.setText("");
                jTextField8.setText("");
                jTextField1.setText("");
                   }catch(Exception ev){
                
                JOptionPane.showMessageDialog(null,"You may Update Suppliers table only during normal business hours");
            }

            }
            if (e.getSource() == jButton6) {

                try{
                String field1 = jTextField10.getText();

                String field3 = jTextField1.getText();
                String field4 = jTextField4.getText();
                String field7 = jTextField5.getText();
                String field8 = jTextField6.getText();

                psmt = conn.createStatement();

                String sqlUpdate = "Update Routes set Route_Name='" + (field3) + "',descr='" + (field4)
                        + "',Address='" + (field7) + "',Surbab='" + (field8) + "' Where Route_Num='" + (field1) + "'";

                psmt.executeUpdate(sqlUpdate);

                JOptionPane.showMessageDialog(null, "Table Routes Updated");
                jTextField10.setText("");
                jTextField1.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
               }catch(Exception ev){
                
                JOptionPane.showMessageDialog(null,"You may Update Routes table only during normal business hours");
            }

            } else if (e.getSource() == jButton7) {

                try{
                String field1 = jTextField10.getText();

                String field3 = jTextField7.getText();
                String field4 = jTextField4.getText();
                psmt = conn.createStatement();

                String sqlUpdate = "Update Subscription set subscr_Type='" + (field3) + "',Descr='" + (field4) + "' Where Subscr_Id='" + (field1) + "'";

                psmt.executeUpdate(sqlUpdate);

                JOptionPane.showMessageDialog(null, "Table Subscription Updated");
                jTextField10.setText("");
                jTextField7.setText("");
                jTextField4.setText("");
               }catch(Exception ev){
                
                JOptionPane.showMessageDialog(null,"'You may Update Subscription table only during normal business hours");
            }

            }
            if (e.getSource() == jButton8) {

                this.dispose();
            }
        } catch (SQLException ex) {
            System.out.println("");
        } finally {

            try {
                if (resultSet != null) {
                    resultSet.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
                if (conn != null) {
                    conn.close();
                }

            } catch (Exception exception) {
                System.out.println("Something went wrong along the way");
            }
        }
    }
}
